﻿// fenshupaihangbang.cpp: 实现文件
//
#include "pch.h"
#include "MFCApplication2.h"
#include "afxdialogex.h"
#include "fenshupaihangbang.h"


// fenshupaihangbang 对话框

IMPLEMENT_DYNAMIC(fenshupaihangbang, CDialogEx)

fenshupaihangbang::fenshupaihangbang(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG2, pParent)
{


}

fenshupaihangbang::~fenshupaihangbang()
{
}

void fenshupaihangbang::DoDataExchange(CDataExchange* pDX)
{
	int n = 0;
	FILE* fp;
	fopen_s(&fp, "..\\Source\\SCORE.txt", "r");
	fscanf_s(fp, "%d", &n);
	int* score = new int[n];
	for (int i = 0; i < n; i++) {
		fscanf_s(fp, "%d", &score[i]);
	}
	fclose(fp);
	switch (n)
	{
	case 0:
		RANK.Format(_T("")); break;
	case 1:
		RANK.Format(_T("1                   %d"), score[0]); break;
	case 2:
		RANK.Format(_T("1                   %d\n2                   %d"), score[0], score[1]); break;
	case 3:
		RANK.Format(_T("1                   %d\n2                   %d\n3                   %d"), score[0], score[1], score[2]); break;
	case 4:
		RANK.Format(_T("1                   %d\n2                   %d\n3                   %d\n4                   %d"), score[0], score[1], score[2], score[3]); break;
	default:
		RANK.Format(_T("1                   %d\n2                   %d\n3                   %d\n4                   %d\n5                   %d"),
			score[0], score[1], score[2], score[3], score[4]);
		break;
	}
	delete score;

	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, TEXT2, RANK);

}


BEGIN_MESSAGE_MAP(fenshupaihangbang, CDialogEx)
	ON_STN_CLICKED(TEXT2, &fenshupaihangbang::OnStnClickedText2)
	ON_STN_CLICKED(VS_VERSION_INFO, &fenshupaihangbang::OnStnClickedVersionInfo)
	ON_BN_CLICKED(IDC_BUTTON1, &fenshupaihangbang::OnBnClickedButton1)
END_MESSAGE_MAP()


// fenshupaihangbang 消息处理程序


void fenshupaihangbang::OnLbnSelchangeList3()
{
	// TODO: 在此添加控件通知处理程序代码
}


void fenshupaihangbang::OnStnClickedText2()
{
	// TODO: 在此添加控件通知处理程序代码
}


void fenshupaihangbang::OnStnClickedVersionInfo()
{
	// TODO: 在此添加控件通知处理程序代码
}


void fenshupaihangbang::OnBnClickedButton1()
{
	FILE* fp;
	fopen_s(&fp, "..\\Source\\SCORE.txt", "w");
	fprintf(fp, "0");
	fclose(fp);

	int n = 0;
	FILE* fp;
	fopen_s(&fp, "..\\Source\\SCORE.txt", "r");
	fscanf_s(fp, "%d", &n);
	int* score = new int[n];
	for (int i = 0; i < n; i++) {
		fscanf_s(fp, "%d", &score[i]);
	}
	fclose(fp);
	switch (n)
	{
	case 0:
		RANK.Format(_T("")); break;
	case 1:
		RANK.Format(_T("1                   %d"), score[0]); break;
	case 2:
		RANK.Format(_T("1                   %d\n2                   %d"), score[0], score[1]); break;
	case 3:
		RANK.Format(_T("1                   %d\n2                   %d\n3                   %d"), score[0], score[1], score[2]); break;
	case 4:
		RANK.Format(_T("1                   %d\n2                   %d\n3                   %d\n4                   %d"), score[0], score[1], score[2], score[3]); break;
	default:
		RANK.Format(_T("1                   %d\n2                   %d\n3                   %d\n4                   %d\n5                   %d"),
			score[0], score[1], score[2], score[3], score[4]);
		break;
	}
	delete score;

	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, TEXT2, RANK);
	// TODO: 在此添加控件通知处理程序代码
}
